package org.example.yongyou;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.ArrayList;
import java.util.HashSet;

public class 销售订单列表查询_bip {
    private static String accessToken = "5eb1eb4048e3457db8c37a72f802a5f7";

    //不解析哪几个字段
    private static HashSet<String> ignore = new HashSet<>();

    static {
        ignore.add("headItem");
        ignore.add("orderDefineCharacter");
        ignore.add("orderDetailCharacteristics");
        ignore.add("orderDetailDefineCharacter");
        ignore.add("bodyItem");
    }

    public static void main(String[] args) {
        String dizhi = "/yonbip/scm/purchaseorder/list";

//        请求地址	/yonbip/scm/othoutrecord/list
//        请求方式	POST
//        data.get("gatewayUrl") = https://c2.yonyoucloud.com/iuap-api-gateway
//        response.getData().getAccessToken() = 9fa5cbb51cc54e9abff982f10a5749e6


        String url = "https://c2.yonyoucloud.com/iuap-api-gateway" + dizhi + "?access_token=" + accessToken;

        //将accessToken放入请求头
        HttpRequest post = HttpUtil.createPost(url);
//      请求体
//        pageIndex	int	 页号         默认值：1
//        pageSize	int	 每页行数       默认值：10
        post.body("{\n" +
                "    \"pageIndex\": 1,\n" +
                "    \"pageSize\": 10,\n" +
                "    \"simpleVOs\": [\n" +
                "      {\n" +
                "    \"op\": \"between\",\n" +
                "    \"value1\": \"2024-08-01 00:00:00\",\n" +
                "    \"field\": \"createTime\",\n" +
//                "    \"logicOp\": \"\",\n" +
                "    \"value2\": \"2024-08-01 23:59:59\"\n" +
                "}" +
                "    ]\n" +
                "}");
        String body = post.execute().body();
        //解析返回的json数据
        JSONObject jsonObject = JSONUtil.parseObj(body);
        Object byPath = jsonObject.getByPath("data.recordList");
        System.out.println(byPath);
        JSONObject data = (JSONObject) jsonObject.get("data");
        JSONArray recordList = (JSONArray) data.get("recordList");

        ArrayList<InsertClass> insertClasses = new ArrayList<>();
        for (Object o : recordList) {
            JSONObject record = (JSONObject) o;//record是每一条记录
            for (String key : record.keySet()) {
                Object o1 = record.get(key);
                if (o1 instanceof JSONObject) {
                    JSONObject jsonObject1 = (JSONObject) o1;
                    for (String s : jsonObject1.keySet()) {
                        System.out.println(key + "_" + s + "--->" + jsonObject1.get(s));
                    }

                }
            }


        }
    }
}

class InsertClass {
    private String enName;
    private String value;

    public String getEnName() {
        return enName;
    }

    public void setEnName(String enName) {
        this.enName = enName;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public InsertClass(String enName, String value) {
        this.enName = enName;
        this.value = value;
    }
}